#pragma once
#include<iostream>
#include<string>
#include<string.h>
#include<arpa/inet.h>
#include<netinet/in.h>

class InetAddr
{
public:
    InetAddr(struct sockaddr_in& addr)
        :_port(addr.sin_port),
        _addr(addr)
    {
        char ip[32];
        struct in_addr ia;
        ia.s_addr=addr.sin_addr.s_addr;
        inet_ntop(AF_INET,&ia,ip,sizeof(ip));
        _ip=ip;
    }

    std::string& Ip()
    {
        return _ip;
    }

    uint16_t Port()
    {
        return _port;
    }
    
    struct sockaddr_in& GetAddr()
    {
        return _addr;
    }

    bool operator==(InetAddr addr)
    {
        return _ip==addr.Ip() && _port==addr.Port();
    }

    ~InetAddr()
    {}
private:
    sockaddr_in _addr;
    uint16_t _port;
    std::string _ip;
};